package com.zdj.websocket.listener;

import org.springframework.context.ApplicationListener;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.messaging.SessionSubscribeEvent;

/**
 * @author zhangdj
 */
@Component
public class SubscribeEventListener implements ApplicationListener<SessionSubscribeEvent> {

    /**
     * StompHeaderAccessor 简单消息协议中处理消息头的基类
     * 通过这个类可以获取消息类型（例如：发布订阅，建立断开链接）、会话id等
     * @param event
     */
    @Override
    public void onApplicationEvent(SessionSubscribeEvent event) {
        StompHeaderAccessor wrap = StompHeaderAccessor.wrap(event.getMessage());
        System.out.println("【监听】 类型" + wrap.getCommand().getMessageType());
    }
}
